﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.WebUsers.Controls
{
    public partial class WUCVisitorSpaceRight : BaseUserControl
    {
        NJL.BLL.NJL_PERSON bllPerson = new BLL.NJL_PERSON();
        NJL.Model.NJL_PERSON modelPerson;
        BLL.NJL_USER bllUser = new BLL.NJL_USER();
        NJL.BLL.NJL_LEAVE_MESSAGE bllMessage = new BLL.NJL_LEAVE_MESSAGE();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bind();
            }
        }
        protected void bind()
        {
            modelPerson = bllPerson.GetModelByUserId(Request.QueryString["uid"]);
            litss.Text = modelPerson.SELF_EVALUATION;
            #region 留言
            DataSet dsMessage = bllMessage.GetList("NJL_USER_ID='" + Request.QueryString["uid"] + "' and LEAVE_MESSAGE_TYPE_CODE=1  ");
            rptCommentList.DataSource = dsMessage;
            rptCommentList.DataBind();
            #endregion
        }
        protected void rptCommentList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                DataRowView grv = (DataRowView)e.Item.DataItem;
                string userId = grv["CREATE_USER_ID"].ToString();
                Image imgUserHead = e.Item.FindControl("imgUserHead") as Image;
                modelPerson = bllPerson.GetModelByUserId(userId);

                LinkButton lbtn = e.Item.FindControl("lbtnDel") as LinkButton;
                if (UserId != "" && UserId.Equals(Request.QueryString["uid"]))
                {
                    lbtn.Visible = true;
                }
                else
                {
                    lbtn.Visible = false;
                }
            }
        }
        protected void rptCommentList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                string id = e.CommandArgument.ToString();
                if (bllMessage.Delete(id))
                {
                    bind();
                }

            }
        }
    }
}